from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from model.ModPowerSupplyBureauOperator import PowerSupplyBureauOperator, bureauOperatorSchema
from database import Session


def get_operator_info(session, openid):
    operators = session.query(PowerSupplyBureauOperator).filter(
        PowerSupplyBureauOperator.openid == openid).one_or_none()
    return JSONResponse(bureauOperatorSchema.dump(operators, many=False).data)


def get_operator_list(session, bureauid):
    operators = session.query(PowerSupplyBureauOperator).filter(
        PowerSupplyBureauOperator.power_supply_bureau == bureauid).filter(
        PowerSupplyBureauOperator.supervision_department != "9").all()
    return bureauOperatorSchema.dump(operators, many=True).data
